package com.loongtech.bi.action.realTime;

import com.loongtech.bi.support.chart.*;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Controller
@Scope("view")
public class Data2Action {
    private ChartUIData chart;
    private List<ChartUIData> pieChartList;

    @PostConstruct
    public void init() {
        search();
    }

    public void search() {
        List<Data> datas = new ArrayList<>();

        Random random = new Random();

        for (int i = 15; i > 0; i--) {
            Data d = new Data();
            d.setTi("第" + i + "题");
            d.setA(random.nextInt(100 - 50 + 1) + 50);
            d.setB(random.nextInt(100 - 50 + 1) + 50);
            d.setC(random.nextInt(100 - 50 + 1) + 50);

            datas.add(d);
        }

        chart = new ChartUIData();
        chart.setJsonType(ChartType.COLUMN.type);
        chart.setJsonStr(new ChartTool(datas, Data.class, "").loadData(chart.getJsonType()));

        pieChartList = new ArrayList<>();
        List<Data1> t = new ArrayList<>();
        Data1 d1 = new Data1();
        d1.setQk("完成");
        d1.setWc(230);
        Data1 d01 = new Data1();
        d01.setQk("未完成");
        d01.setWc(150);
        t.add(d1);
        t.add(d01);

        List<Data1> t1 = new ArrayList<>();
        Data1 d11 = new Data1();
        d11.setQk("小于5分钟");
        d11.setYs(14);
        Data1 d12 = new Data1();
        d12.setQk("小于10分钟");
        d12.setYs(210);
        Data1 d13 = new Data1();
        d13.setQk("大于10分钟");
        d13.setYs(70);
        t1.add(d11);
        t1.add(d12);
        t1.add(d13);

        for (int i = 1; i <= 2; i++) {
            ChartUIData ct = new ChartUIData();
            ct.setJsId(i + "");
            ct.setJsonStr(new ChartTool(i == 1 ? t : t1, Data1.class, i == 1 ? "wc" : "ys").loadData("pie"));

            System.out.println(ct.getJsonStr());
            ct.setJsonType(ChartType.PIE.type);
            ct.setHeader(i == 1 ? "问卷完成情况" : "问卷用时情况");
            pieChartList.add(ct);
        }
    }

    public class Data1 {
        @ChartFlow(name = "情况")
        private String qk;
        @ChartSelect(name = "问卷完成情况", key = 1)
        @ChartData1(name = "问卷完成情况", key = 1)
        private int wc;
        @ChartSelect(name = "问卷用时情况", key = 2)
        @ChartData1(name = "问卷用时情况", key = 2)
        private int ys;

        public String getQk() {
            return qk;
        }

        public void setQk(String qk) {
            this.qk = qk;
        }

        public int getWc() {
            return wc;
        }

        public void setWc(int wc) {
            this.wc = wc;
        }

        public int getYs() {
            return ys;
        }

        public void setYs(int ys) {
            this.ys = ys;
        }
    }

    public class Data {
        @ChartFlow(name = "题目")
        private String ti;
        @ChartSelect(name = "留存率", key = 1)
        @ChartData1(name = "A", key = 1)
        private int a;
        @ChartData1(name = "B", key = 1)
        private int b;
        @ChartData1(name = "C", key = 1)
        private int c;

        public String getTi() {
            return ti;
        }

        public void setTi(String ti) {
            this.ti = ti;
        }

        public int getA() {
            return a;
        }

        public void setA(int a) {
            this.a = a;
        }

        public int getB() {
            return b;
        }

        public void setB(int b) {
            this.b = b;
        }

        public int getC() {
            return c;
        }

        public void setC(int c) {
            this.c = c;
        }
    }

    public ChartUIData getChart() {
        return chart;
    }

    public void setChart(ChartUIData chart) {
        this.chart = chart;
    }

    public List<ChartUIData> getPieChartList() {
        return pieChartList;
    }

    public void setPieChartList(List<ChartUIData> pieChartList) {
        this.pieChartList = pieChartList;
    }
}
